package org.aplikator.client.local.widgets;

import com.github.gwtbootstrap.client.ui.Column;
import com.github.gwtbootstrap.client.ui.FluidRow;
import com.github.gwtbootstrap.client.ui.base.DivWidget;
import com.google.gwt.core.client.GWT;
import com.google.gwt.resources.client.ClientBundle;
import com.google.gwt.resources.client.CssResource;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;

public class PaneWidget extends Composite {

    public interface PaneWidgetResources extends ClientBundle {
        public static final PaneWidgetResources INSTANCE = GWT.create(PaneWidgetResources.class);

        @Source("PaneWidget.css")
        public PaneWidgetCss css();
    }

    public interface PaneWidgetCss extends CssResource {
        public String panelBorder();

        public String formLabel();

        public String formData();
    }

    static {
        PaneWidgetResources.INSTANCE.css().ensureInjected();
    }

    protected DivWidget panel;

    protected Label label;

    public PaneWidget(String label, boolean framed, boolean horizontal, int size) {
        if (horizontal) {
            panel = new FluidRow();
        } else {
            panel = new Column(size>0?size:1);
        }

        /*if (horizontal) {
            panel = new HorizontalFlowPanel();
        } else {
            panel = new VerticalFlowPanel();
        } */
        // panel.setWidth("100%");
        //panel.setSpacing(2);
        if (horizontal && size>0 && size <12){
            FluidRow wrapper = new FluidRow();
            Column sizerColumn = new Column(size);
            sizerColumn.add(panel);
            wrapper.add(sizerColumn);
            initWidget(wrapper);
        }   else{
            initWidget(panel);
        }
        if (label != null || "".equals(label)) {
            this.label = new Label(label);
            this.label.addStyleName(PaneWidgetResources.INSTANCE.css().formLabel());
            add(this.label);
        }
        if (framed) {
            panel.addStyleName(PaneWidgetResources.INSTANCE.css().panelBorder());
        }

    }

    public void add(Widget widget) {
        panel.add(widget);
    }

}
